package com.kadron.transaction;

import javax.transaction.UserTransaction;

import com.kadron.exceptions.KBeginException;
import com.kadron.exceptions.KCommitException;

public class KTx {

	public static void begin(UserTransaction tx) throws KBeginException {
		if (tx == null) {
			return;
		}
		try {
			tx.begin();
		} catch (Exception e) {
			throw new KBeginException(e);
		}
	}
	
	public static void commit(UserTransaction tx) throws KCommitException {
		if (tx == null) {
			return;
		}
		try {
			tx.commit();
		} catch (Exception e) {
			throw new KCommitException(e);
		}
	}
	
	public static void rollback(UserTransaction tx) {
		if (tx == null) {
			return;
		}
		try {
			tx.rollback();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
